package com.hxzy.controller.front.dictdata;

import com.hxzy.common.enums.AckCode;
import com.hxzy.common.resp.R;
import com.hxzy.common.util.DictDataCacheUtil;
import com.hxzy.controller.vue.dictdata.resp.SysDictDataResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Author wy
 * @Description TODO
 * @Date 2023/9/25 15:05
 * @Version 1.0
 */
@Api(tags = "手机端-通用字典")
@RestController
@RequestMapping(value = "/front/dictdata")
public class FrontDictDataController {

    @Autowired
    private DictDataCacheUtil  dictDataCacheUtil;

    // http://localhost:8080/front/dictdata/bynames?dicts=sys_user_sex
    // http://localhost:8080/front/dictdata/bynames?dicts=sys_user_sex&dicts=sys_normal_disable
    @ApiOperation(value = "根据dictType去缓存中查询值")
    @GetMapping(value = "/bynames")
    public R findByDictType( String[] dicts){
        Map<String,List<SysDictDataResp>>  dataMap=new HashMap<>();
        for(String key : dicts){
            List<SysDictDataResp> byDictType = this.dictDataCacheUtil.findByDictType(key);
            //redis缓存穿透
            if(byDictType.isEmpty()){
                R.build(AckCode.NOT_FOUND_DATA);
            }
            dataMap.put(key, byDictType);
        }
        return R.okHasData(dataMap);
    }
}
